Let's get started by importing a few moduled used in this tutorial.
In [1]:
from IPython.display import Image
In [2]:
print("Hello, world!")
That works, but we can also first store the content in a variable, and then print out the variable.
In [3]:
string = "Hello, world!"
print(string)
Let's work with something more interesting... a dataset provided by Earth Engine.
Assuming that this server has been setup with access to the Earth Engine Python API, we should be able to import and initialise the Earth Engine Python module (named 'ee'). If the module loads successfully, nothing will be returned when you run the following code.
In [4]:
import ee
ee.Initialize()
Next, let's locate a dataset to display. Start by going to the Earth Engine Public Data Catalog (https://earthengine.google.org/#index).
In [5]:
Image('http://www.google.com/earth/outreach/images/tutorials_eeintro_05_data_catalog.png')
Out[5]:
Type in the term SRTM in the search box, click the search button, and then select the dataset SRTM Digital Elevation Data Version 4 from the list of results. This will bring up a data description page for the SRTM Digital Elevation Data 30m dataset. The data description page provide a short description of the dataset and links to the data provider, but the key piece of information that we need for working with the dataset in Earth Engine is the Image ID, which for this dataset is CGIAR/SRTM90_V4. Let's use the Image ID to store a reference to this image dataset:
In [6]:
srtm = ee.Image("CGIAR/SRTM90_V4")
And now, we can print out information about the dataset, using the .getInfo() method.
In [7]:
info = srtm.getInfo()
print(info)
What is returned by the .getInfo() command is a Python dictionary. If needed, we could parse out this information and make use of it in our analysis.
In [8]:
from IPython.display import Image
Image(url=srtm.getThumbUrl())
Out[8]:
Ok, we can see the outlines of the continents, but there is not a lot of contrast between different elevation areas. So let's improve upon that, but adding some visualization parameters.
In [9]:
Image(url=srtm.getThumbUrl({'min':0, 'max':3000}))
Out[9]:
By default, the .getThumbUrl() method returns the entire extent of the image, which in this case is global. We can also specify a region, to show a smaller area.
In [10]:
point = ee.Geometry.Point(-122.0918, 37.422)
region_bay_area = point.buffer(50000).bounds().getInfo()['coordinates']
Image(url=srtm.getThumbUrl({'min':0, 'max':1000, 'region':region_bay_area}))
Out[10]:
So far we have been working with a single image, but there are also interesting datasets that are distributed as a series of images (such as images collected by satellite). Head back to the Earth Engine Public Data Catalog, search for landsat 8 toa, and load up the data description page for the USGS Landsat 8 TOA Reflectance (Orthorectified) dataset. The ID for this Image Collection is LANDSAT/LC8_L1T_TOA.
In [11]:
# Create a reference to the image collection
l8 = ee.ImageCollection('LANDSAT/LC8_L1T_TOA')
# Filter the collection down to a two week period
filtered = l8.filterDate('2013-05-01', '2013-05-15');
# Use the mosaic reducer, to select the most recent pixel in areas of overlap
l8_image = filtered.mosaic()
# Define a region roughly covering California
point = ee.Geometry.Point(-118, 37)
region_california = point.buffer(500000).bounds().getInfo()['coordinates']
# And finally display the image.
Image(url=l8_image.getThumbUrl({'region':region_california}))
Out[11]:
In [12]:
Image(url=l8_image.getThumbUrl({
'region':region_california,
'bands':'B4,B3,B2',
'min':0,
'max':0.3
}))
Out[12]:
And by changing the bands displayed, we can also display a false color image.
In [13]:
Image(url=l8_image.getThumbUrl({
'region':region_california,
'bands':'B5,B4,B3',
'min':0,
'max':0.3
}))
Out[13]:
In [14]:
filtered = l8.filterDate('2013-01-01', '2014-01-01')
In [15]:
l8_image = filtered.mosaic()
Image(url=l8_image.getThumbUrl({
'region':region_california,
'bands':'B4,B3,B2',
'min':0,
'max':0.3
}))
Out[15]:
In [16]:
l8_image = filtered.median()
Image(url=l8_image.getThumbUrl({
'region':region_california,
'bands':'B4,B3,B2',
'min':0,
'max':0.3
}))
Out[16]:
In [17]:
l8_image = filtered.min()
Image(url=l8_image.getThumbUrl({
'region':region_california,
'bands':'B4,B3,B2',
'min':0,
'max':0.3
}))
Out[17]:
In [18]:
l8_image = filtered.max()
Image(url=l8_image.getThumbUrl({
'region':region_california,
'bands':'B4,B3,B2',
'min':0,
'max':0.3
}))
Out[18]:
In [ ]: